/**
 * 剑指 Offer 46. 把数字翻译成字符串
 * https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/
 */

/**
 * @param {number} num
 * @return {number}
 */
function translateNum(num) {
  const str = String(num);
  let dp = 1;
  let dpPre = 1;
  for (let i = 1; i < str.length; i += 1) {
    let count = dp;
    const preChar = str[i - 1];
    const char = str[i];
    if (
      preChar === '1'
      || (preChar === '2' && char <= '5')
    ) {
      count += dpPre;
    }
    dpPre = dp;
    dp = count;
  }
  return dp;
}

console.log(translateNum(12258) === 5);
console.log(translateNum(25) === 2);
console.log(translateNum(1620322624) === 16);
